/*
 *  $Id: BrainLock.cs 1221 2010-11-30 16:54:52Z thenn.erannor $
 *	This file is a part of Ragima CCG.
 *	(C) 2008 Ragima development group.
 *
 *	Licensed under the terms of the GNU GPL License version 2.
 *
 */

namespace Ragima.Cards001.Water.Spells {
    public class BrainLock: EnchantmentCard<int> {
        public BrainLock(): base("001_w_s_brain_lock") {
            Level = CompleteLevel.ReadyForTest;
            Element = ElementType.Water;
            Value = 100;
            Target = new JogTarget(GetTargetPhrase(), GetJogValue);
            AddManaCost(ElementType.Water, 4);
            AddCondition(HandCardsCondition.Own(1));
        }

        private static IJogValueProvider GetJogValue(Player player) {
            return new CardJogValueProvider(player);
        }

        private int _value;

        protected override void DoAction(TargetArgs<int> args) {
            args.Player.ReleaseCards(args.Target);
            _value = args.Target + 1;
            base.DoAction(args);
        }
        protected override AbstractObject GetTarget(TargetArgs<int> args) {
            return args.Player.Enemy;
        }
        protected override EnchantmentAffect CreateEnchantment() {
            return new BrainLockAffect(_value);
        }

        private class BrainLockAffect: EnchantmentAffect<BrainLock> {
            private static readonly Languages.CardPhrase<BrainLock> LockMessage = new Languages.CardPhrase<BrainLock>("lock");

            private TimeAffect _affect;

            public BrainLockAffect(int turns): base(true) {
                DefaultDescription = true;
                _affect = new TimeAffect(turns, TimePhase.OwnOffence, new Affects.LockCards(IsTargetSpell, LockMessage.Phrase));
                Add(_affect);
            }

            private static bool IsTargetSpell(Player player, Card card) {
                return card.IsSpell && card.Target != null ? card.Target.IsRealTarget : false;
            }

            public override string Id {
                get { return AffectManager.GetCardId<BrainLock>(null); }
            }

            public override string DescriptionText {
                get { return Description.GetText(_affect.Phases/4); }
            }

            public override Affect Clone() {
                return new BrainLockAffect(_affect.Phases);
            }
        }
    }
}
